include_dir = ./include/
include_db_dir =  /usr/include/mysql
lib_dir = ./lib/
src_dir = ./src/
build_dir = ./build/
lib1 = lby_sys_tools
lib2 = lby_comm_tools
lib3 = cjh_db_tools

target1 = snds_main
src_type = .cpp
src1 = $(src_dir)$(target1)$(src_type)

other_src = $(src_dir)dispatch.cpp $(src_dir)cjh_db_tools.cpp

config_dir = /home/G1851441/
config_file = config.json

compile = g++
cflags = -I$(include_dir) -L$(lib_dir) -l$(lib1) -l$(lib2) `mysql_config --cflags` `mysql_config --include` `mysql_config --libs`

.PHONY : all
all : server

.PHONY : server
server : $(src1)
	if [ ! -d $(build_dir) ]; then \
		mkdir $(build_dir); \
	fi
	$(compile) -o  $(build_dir)$(target1) $(src1) $(other_src) $(cflags) 
	if [ ! -d $(config_dir) ]; then \
		mkdir -p $(config_dir); \
	fi
	cp $(config_file) $(config_dir)$(config_file)


.PHONY : clean
clean : 
	rm -rf $(build_dir)

.PHONY : remake
remake:
	rm -rf $(config_dir)log.txt
	rm -rf $(config_dir)real_file_dir/*
	mysql -uu1851441 -pu1851441 < ./db/createdatabase.sql
	killall snds_main

